package com.game.beans;

import com.game.GameWindow;
import com.game.utils.GameUtils;

import java.awt.*;
import java.awt.image.BufferedImage;

public class EnemyBean extends GameBean{
    public EnemyBean() {
        super();
    }

    public EnemyBean(BufferedImage img, int x, int y, double speed) {
        super(img, x, y, speed);
    }

    public EnemyBean(BufferedImage img, int x, int y, int width, int height, double speed, GameWindow frame) {
        super(img, x, y, width, height, speed, frame);
    }

    @Override
    public void paintSelf(Graphics graphics) {
        super.paintSelf(graphics);
        y += speed;
        if (GameWindow.enemyDestoried > 50){
            x += this.frame.random.nextInt((int)(this.speed * 2)) - this.speed;
            if (x < 5){
                x = 5;
            } else if (x > GameWindow.WIDTH - 10) {
                x = GameWindow.WIDTH - 10;
            }
        }
        for (ShellBean shellBean:GameUtils.shellBeans
             ) {
            if (this.getRectangle().intersects(shellBean.getRectangle())){
                this.remove(-100,-100);
                shellBean.remove(-50,-50);
                GameWindow.enemyDestoried += 1;

            }
        }
        if (y > GameWindow.HEIGHT){
            super.remove(-100,-100);
        }
    }

    @Override
    public Rectangle getRectangle() {
        return super.getRectangle();
    }
}
